package com.springinaction.ch04.noargs;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class Audience {
    @Pointcut("execution(* com.springinaction.ch04.noargs.Performance.perform(..))")
    public void performance(){}
/*
    @Before("performance()")
    public void silenceCellPhones(){
        System.out.println("Silence cell phones");
    }
    @After("execution(* com.springinaction.ch04.noargs.Performance.perform(..))")
    public void takeSeats(){
        System.out.println("Taking seats");
    }
    @AfterReturning("execution(* com.springinaction.ch04.noargs.Performance.perform(..))")
    public void applause(){
        System.out.println("CLAP CLAP CLAP!!!");
    }
    @AfterThrowing("execution(* com.springinaction.ch04.noargs.Performance.perform(..))")
    public void demandRefund(){
        System.out.println("Demanding a refund");
    }
*/
   @Around("performance()")
   public void watchPerformance(ProceedingJoinPoint pj){
       try {
           try {
               System.out.println("Silence cell phones");
               pj.proceed();
           }finally {
               System.out.println("Taking seats");
           }
           System.out.println("CLAP CLAP CLAP!!!");

       }catch (Throwable e){
           System.out.println("Demanding a refund");
       }
   }
}
/* 执行顺序
try{
    try{
        //@Before
        method.invoke(..);
    }finally{
        //@After
    }
    //@AfterReturning
}catch(){
    //@AfterThrowing
}

 */